class Solution {
public:
    vector<int> findSubstring(string s, vector<string>& words) {
       vector<int> ret;
       unordered_map<string,int> hash1;
       for(auto&ch:words) hash1[ch]++;
       int len=words[0].size();
       for(int i=0;i<len;i++)
       {
             unordered_map<string,int> hash2;
        for(int left=i,right=left,count=0;right+len<=s.size();right+=len)
        {
            string key=s.substr(right,len);
            hash2[key]++;
            if(hash1.find(key)!=hash1.end()&& hash2[key]<=hash1[key])
            {
                count++;
            }
            //出窗口
            if(right-left>=words.size()*len)
            {
                string tem=s.substr(left,len);
                if(hash1.find(tem)!=hash1.end()&&hash2[tem]<=hash1[tem])
                {
                    count--;
                }
                hash2[tem]--;
                left+=len;
            }
            if(count==words.size()) 
            {
                ret.push_back(left);
            }
        }
       }
       return ret;
    }
};